package com.practice.car.cardataapp.schelduer.spark.entityForSpark;

import org.apache.spark.api.java.function.FlatMapFunction;
import org.codehaus.jackson.map.ObjectMapper;

import java.util.ArrayList;
import java.util.Iterator;

public class ParseJson implements FlatMapFunction<Iterator<String>, CarMessage> {

    public Iterator<CarMessage> call(Iterator<String> lines) throws Exception{
        ArrayList<CarMessage> list = new ArrayList<CarMessage>();
        ObjectMapper mapper = new ObjectMapper();
        while(lines.hasNext()){
            String line = lines.next();
            try{
                list.add(mapper.readValue(line,CarMessage.class));
            }catch (Exception e ){

            }
        }
        return list.iterator();
    }

}
